$(document).ready(function(){
    var windowWidth = $(window).width();
	if (!localStorage.getItem("tip") && windowWidth>1000) {
        showtip();
    }
    $('#addallqrcodeModal').on('hidden.bs.modal', function () {
        // 在此处添加您要执行的代码
        if(kfQrcodes.length == 0 && $("#qrcode_name").val() == ''){
            qrcodesListsAllImagesAdd();
        }
    });
});

function showtip(index=0){
    var item = tipJson[index];
    var top,left;
    top=$('#linkDetialTable li[data="'+ item.cssname +'"]').offset().top;
    left=$('#linkDetialTable li[data="'+ item.cssname +'"]').offset().left;
    var width1 = $('#linkDetialTable li[data="'+ item.cssname +'"]').width();
    var width2 = $('#contrtent').width();
    console.log(width2);
    var height1 = $('#linkDetialTable li[data="'+ item.cssname +'"]').height();
    var t_left = Math.floor(width1 / 2 -  width2/2);
    var t_top = height1 + 15;
    $("#contrtent").css('top',top+'px');
    $("#contrtent").css('left',left+'px');
    $("#contrtent").css('transform','translateX('+t_left+'px) translateY('+t_top+'px)');
    var html = "";
    if(item.image.length > 5) {
        html += '<img src="'+ item.image +'">';
    }
    let nextindex = index+1;
    let previousindex = index-1;
    html += '<font class="controls-title">'+item.name+'</font><font class="controls-des">'+item.content+'</font>';
    if(index==0){
        html += '<div class="next-content"><span class="next" onclick="showtip('+nextindex+')">下一步</span></div>'
    }else if(index == tipJson.length-1){
        html += '<div class="next-content"><span class="previous" onclick="showtip('+previousindex+')">上一步</span><span class="next" onclick="endtip()">结束导览</span></div>'
    }else{
        html += '<div class="next-content"><span class="previous" onclick="showtip('+previousindex+')">上一步</span><span class="next" onclick="showtip('+nextindex+')">下一步</span></div>'
    }
    $("#housing").html(html);
    $("#controls").show();
    setTimeout(()=>{
        $('#linkDetialTable li[data="'+ item.cssname +'"]').trigger("click");
    },300)
}
function endtip(){
    localStorage.setItem("tip",1);
    if(kfQrcodes.length == 0 && $("#qrcode_name").val() == ''){
        $('#linkDetialTable li[data="qrcode"]').trigger("click");
    }else {
        $('#linkDetialTable li[data="copy"]').trigger("click");
    }
    $("#controls").hide();
}